﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AzureDiagnostics2Excel
{
    public partial class AddAccountWindow : Form
    {
        public AddAccountWindow()
        {
            InitializeComponent();

            buttonAddAccount.DialogResult = DialogResult.OK;
        }

        private void buttonAddAccount_Click(object sender, EventArgs e)
        {
            if (this.textBoxAccountName == null || this.textBoxAccountKey == null)
            {
                MessageBox.Show("Please enter the account name and the account key.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            string connectionString = "DefaultEndpointsProtocol=https;AccountName=" + this.textBoxAccountName.Text + ";AccountKey=" + this.textBoxAccountKey.Text;

            System.Configuration.SettingsProperty newSetting = new System.Configuration.SettingsProperty(this.textBoxAccountName.Text);
            newSetting.IsReadOnly = false;
            newSetting.PropertyType = typeof(string);
            newSetting.DefaultValue = connectionString;
            Properties.Settings.Default.Properties.Add(newSetting);
            Properties.Settings.Default.Save();
        }
    }
}
